package com.vcar.LDiceClient.module.gameModule
{
	/**
	 * Module例子
	 * @author Rices
	 * 定义模型基本结构
	 */
	
	
	import caurina.transitions.Tweener;
	
	import com.vcar.LDiceClient.config.GlobalEventName;
	import com.vcar.LDiceClient.config.MediatorName;
	import com.vcar.LDiceClient.config.ProxyNames;
	import com.vcar.LDiceClient.dataproxy.RequestMessage;
	import com.vcar.LDiceClient.dataproxy.ResponseMessage;
	import com.vcar.LDiceClient.dataproxy.SocketProxy;
	import com.vcar.LDiceClient.dataproxy.user.UserProxy;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.events.TimerEvent;
	import flash.geom.Point;
	import flash.utils.Timer;
	
	import mx.collections.ArrayCollection;
	import mx.controls.Label;
	
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	public class gameModuleMediator extends Mediator
	{
		/**
		 * 构造函数
		 * @param viewComponent
		 */
		public function gameModuleMediator(viewComponent:Object=null)
		{
			super(MediatorName.gameModuleMediator, viewComponent);
			init();
			
		}
		
		/**
		 * 获取Module实例
		 * @return
		 */
		public function get view():gameModule
		{
			return viewComponent as gameModule;
		}
		
		/**
		 * 定义兴趣事件列表
		 * @return
		 */
		override public function listNotificationInterests():Array
		{
			return [GlobalEventName.GAME_ENTER_SUSS,
				GlobalEventName.STORE_SITDOWN_SUSS,
				GlobalEventName.GAME_READY_SUSS,
				GlobalEventName.GAME_BEGIN_SUSS,
				GlobalEventName.GAME_CALLDICE_SUSS,
				GlobalEventName.GAME_OPEN_SUSS,
				GlobalEventName.STORE_STANDUP_SUSS,
				GlobalEventName.GAME_END_SUSS
			];
		}
		
		/**
		 * 兴趣事件处理函数
		 * @param notification
		 */
		override public function handleNotification(notification:INotification):void
		{
			var obj:ResponseMessage=notification.getBody() as ResponseMessage;
			switch (notification.getName())
			{	
				
				case GlobalEventName.GAME_ENTER_SUSS:
				{	
					
					view.testC.visible=false;
					var p:UserProxy=facade.retrieveProxy(ProxyNames.UserProxy) as UserProxy;
					UserId=p.currentUserVO.username;					
					myDeskId=obj.object.gameInfo.deskId;					
					getGameInfo(obj.object,myDeskId);
					gameLoad();						
				}					
					break;
				
				case GlobalEventName.STORE_SITDOWN_SUSS:
				{
					deskId=obj.object.deskId;					
					if (deskId==myDeskId)
					{
						var x:int=obj.object.seatX;
						var y:int=obj.object.seatY;						
						addPlayer(x,y);	
					}					
				}
					break;
				
				case GlobalEventName.GAME_READY_SUSS:
				{
					deskId=obj.object.deskId;
					if (deskId==myDeskId)
					{
						getGameReady(obj.object);
					}
				}
					break;
				
				case GlobalEventName.GAME_BEGIN_SUSS:
				{						
					if(obj.target==UserId)
					{
						gameBegin(obj.object);
					}
					
				}
					break;
				
				case GlobalEventName.GAME_OPEN_SUSS:
				{
					if(obj.object.openDice==1)
					{						
						diceText.callTextBox.text="Open!開！";
						diceText.callTextBox.textColor=0xfebecc;
					} 
					else
					{
						diceText.callTextBox.text="PI!劈死你！";
					}
					diceText.x=agameSeatCoordinate[obj.object.seatId].x;
					diceText.y=agameSeatCoordinate[obj.object.seatId].y;
					var overTime:Timer=new Timer(2000,1);					
					overTime.start();
					overTime.addEventListener(TimerEvent.TIMER,overDice);
					gameSta.callButton.removeEventListener(MouseEvent.CLICK,callDice);		
					gameSta.kaiButton.removeEventListener(MouseEvent.CLICK,openDice);	
					gameSta.piButton.removeEventListener(MouseEvent.CLICK,openDice);
				}
					break;
				
				case GlobalEventName.GAME_END_SUSS:
				{	
					var kongge:String=" "+" "+" "+" "+" "+" "+" "+" "+" "+" "+" "+" ";
					var gamePlayerInfo:Array=new Array();
					for (var i:String in obj.object.gameResult)
					{
						gamePlayerInfo.push({
							"label":	i+kongge+obj.object.gameResult[i]							
						});						
					}					
					view.shopList.dataProvider=gamePlayerInfo;
					view.testC.visible=true;
					view.gameAgain.addEventListener(MouseEvent.CLICK,gameRestart);
				}
					break;
				
				
				case GlobalEventName.STORE_STANDUP_SUSS:
				{
					deskId=obj.object.deskId;					
					if (deskId==myDeskId)
					{				
						removePlayer(obj.object.seatX,obj.object.seatY);	
					}					
				}
					break;
				
				
				case GlobalEventName.GAME_CALLDICE_SUSS:
				{						
					diceText.visible=true;
					if(obj.object.diceNow%6==0)
					{
						showDiceText.textDice.gotoAndStop(1);
						if(obj.object.diceNow<67)
						{
							showDiceText.textTen.visible=false;
							showDiceText.textOne.gotoAndStop(Math.floor(obj.object.diceNow/6)-1);
						}
						else if(obj.object.diceNow==126)
						{
							showDiceText.textTen.visible=true;
							showDiceText.textOne.gotoAndStop(10);
							showDiceText.textTen.gotoAndStop(2);
						}
						else
						{
							showDiceText.textTen.visible=true;
							showDiceText.textOne.gotoAndStop(Math.floor(obj.object.diceNow/6)-11);
							showDiceText.textTen.gotoAndStop(10);
						}
						diceText.callTextBox.text=(obj.object.diceNow/6-1)+"个"+1;
					}
					else{
						showDiceText.textDice.gotoAndStop(obj.object.diceNow%6+1);
						if(int(obj.object.diceNow/6)<=10)
						{
							showDiceText.textTen.visible=false;
							showDiceText.textOne.gotoAndStop(Math.floor(obj.object.diceNow/6));
						}
						else if((Math.floor(obj.object.diceNow/6))==20)
						{
							showDiceText.textTen.visible=true;
							showDiceText.textOne.gotoAndStop(10);
							showDiceText.textTen.gotoAndStop(2);
						}
						else{
							showDiceText.textTen.visible=true;
							showDiceText.textOne.gotoAndStop(Math.floor(obj.object.diceNow/6)-10);
							showDiceText.textTen.gotoAndStop(10);
						}
						diceText.callTextBox.text=(Math.floor(obj.object.diceNow/6))+"个"+(obj.object.diceNow%6+1);
					}
					callDiceMovie(obj.object.callPlayer);
					if(obj.object.playNow==mySeat)
					{
						nowCall=obj.object.playNow;
						gameRun();						
					}
				}	
					break;
			}
		}
		/**
		 * 下面为功能代码
		 */	
		private var callTime:Timer=new Timer(3000,0);
		private var deskId:int;
		private var UserId:String;
		private var myDeskId:int=0;
		private var agameInfo:Object;
		private var gameSta:gameStage= new gameStage();	
		private var changeDiceBox:diceChangeShow=new diceChangeShow();
		private var showDiceText:showDiceBox=new showDiceBox();
		private var diceText:callTextBoxx=new callTextBoxx();
		private var playerNum:int;	
		private var gameInfo:Object;
		private var userList:ArrayCollection;
		private var gameSeatCoordinate:Array=new Array();
		private var agameSeatCoordinate:Array=new Array();
		private var mySeat:int;
		private var intervalId:uint;
		private var calculateTimeInt:int=0;
		private var nowCall:int;
		private var myDiceArray:Array=new Array();
		
		
		
		private function init():void
		{
			
			var reMessage:RequestMessage = new RequestMessage();
			var proxy:SocketProxy = facade.retrieveProxy(ProxyNames.SocketProxy) as SocketProxy;
			reMessage.type=8;
			reMessage.subtype=7;
			proxy.send(reMessage);
			
		}		
		
		/**
		 *获取游戏信息
		 * @param obj
		 * @param deskId
		 *
		 */		
		private function getGameInfo(obj:Object,deskId:int):void
		{			
			
			gameInfo=obj.gameInfo;					//台子信息
			userList=gameInfo.userList;		//本台玩家信息	
			var playing:Boolean=gameInfo.playing;   //游戏状态，时候进行中
			playerNum=userList.length; //当前玩家数目
			gameSeatCoordinate=[new Point(200,360),new Point(300,260),new Point(200,160),new Point(100,260)];
			agameSeatCoordinate=[new Point(200,300),new Point(250,250),new Point(200,190),new Point(150,250)];	
			for (var i:int=0;i<playerNum;i++)
			{
				if(userList[i]['userId']==UserId)
				{
					mySeat=findThisSeat(userList[i]["seatX"],userList[i]["seatY"]);
					trace(mySeat);
					break;
				}					
			}			
		}
		
		/**
		 * 发送准备信息，并请求返回信息
		 *
		 */		
		private function gameReady(e:Event=null):void
		{
			var reMessage:RequestMessage = new RequestMessage();
			var proxy:SocketProxy = facade.retrieveProxy(ProxyNames.SocketProxy) as SocketProxy;
			reMessage.type=7;
			reMessage.subtype=4;
			proxy.send(reMessage);
			
		}
		
		/**
		 *接受准备信息
		 * @param obj	接受内容
		 * @param readyName		准备者
		 *
		 */		
		private function getGameReady(obj:Object):void
		{
			
			var gameSeat:String=String(findThisSeat(obj.seatX,obj.seatY));
			var readyStae:Boolean=obj.ready;			
			if(readyStae==true)
			{
				(view.gameLayer.getChildByName(gameSeat) as gamePlayer).alpha=1;
			}
			if(readyStae==false)
			{
				(view.gameLayer.getChildByName(gameSeat) as gamePlayer).alpha=0.5;
			}
			
		}
		/**
		 * 用户加入使加载用户头像
		 * @param x
		 * @param y
		 *
		 */		
		private function addPlayer(x:int,y:int):void
		{
			var playPic:gamePlayer=new gamePlayer();
			playPic.alpha=0.5;
			gameSeatSet(playPic,x,y);
			view.gameLayer.addChild(playPic);
		}
		
		private function removePlayer(x:int,y:int):void
		{
			if(findThisSeat(x,y)==mySeat)
			{
				
			}
			else
			{
				view.gameLayer.removeChild(view.gameLayer.getChildByName(String(findThisSeat(x,y))));
			}
			
		}
		
		private function gameSeatSet(playPic:gamePlayer,itemX:int,itemY:int):void
		{				
			var gameSeat:int=findThisSeat(itemX,itemY);			
			playPic.x=gameSeatCoordinate[gameSeat].x;
			playPic.y=gameSeatCoordinate[gameSeat].y;
			playPic.name=String(gameSeat);			
		}
		
		/**
		 *游戏组件加载
		 *
		 */		
		private function gameLoad():void
		{				
			view.main.verticalScrollPolicy=view.main.horizontalScrollPolicy="off";
			view.gameLayer.addChild(gameSta);
			gameSta.name="gameSta";
			view.gameLayer.x=view.gameLayer.y=0;			
			
			var desk:tablePic=new tablePic();
			gameSta.addChild(desk);
			desk.x=200;
			desk.y=260-20;
			desk.scaleX=desk.scaleY=0.65;
			gameSta.setChildIndex(desk,3);
			gameSta.box.x=agameSeatCoordinate[3].x;
			gameSta.box.y=agameSeatCoordinate[3].y;
			//背景图设置居中置底
			gameSta.picBg1.x=gameSta.picBg2.x=view.gameLayer.width*0.5;
			gameSta.picBg1.y=gameSta.picBg2.y=view.gameLayer.height*0.5;
			gameSta.setChildIndex(gameSta.picBg1,0);
			gameSta.setChildIndex(gameSta.picBg2,1);
			
			
			//			gameSta.textPlane.x=view.gameLayer.width-45-gameSta.textPlane.width*0.5;
			//			gameSta.textPlane.y=45+gameSta.textPlane.height*0.5;
			//			gameSta.textDice.x=gameSta.textPlane.x+0.35*gameSta.textPlane.width;
			//			gameSta.textDice.y=gameSta.textPlane.y-15;
			//			gameSta.textTen.x=gameSta.textPlane.x-0.35*gameSta.textPlane.width;
			//			gameSta.textTen.y=gameSta.textPlane.y-5;
			//			gameSta.textOne.x=gameSta.textPlane.x-10;
			//			gameSta.textOne.y=gameSta.textPlane.y-5;
			//			
			//			gameSta.diceShowMc.x=view.gameLayer.width-gameSta.changeDiceMc.width*0.5-10;
			//			gameSta.diceShowMc.y=view.gameLayer.height*0.5+90;
			//			
			//			gameSta.changeDiceMc.x=view.gameLayer.width-gameSta.changeDiceMc.width*0.5-10;
			//			gameSta.changeDiceMc.y=view.gameLayer.height*0.5-35;			
			
			//桌子内容显示
			
			
			//工具栏工具
			gameSta.callDice.x=0.5*view.gameLayer.width+30;
			gameSta.callDice.y=view.gameLayer.height-55-gameSta.kaiButton.height*0.5+10;
			gameSta.callButton.x=view.gameLayer.width-35-gameSta.callButton.width;
			gameSta.kaiButton.x=view.gameLayer.width-162-gameSta.kaiButton.width;			
			gameSta.kaiButton.y=gameSta.callButton.y=view.gameLayer.height-55-gameSta.kaiButton.height*0.5;
			gameSta.arrowDown.x=gameSta.arrowUp.x=gameSta.callDice.x;
			gameSta.numArrowDown.y=gameSta.arrowDown.y=view.gameLayer.height-40;			
			gameSta.numArrowUp.y=gameSta.arrowUp.y=view.gameLayer.height-150;
			gameSta.arrowDown.scaleY=-1;			
			gameSta.otherBtn1.gotoAndStop(1);
			gameSta.otherBtn1.x=view.gameLayer.width*0.5-50;
			gameSta.otherBtn1.y=gameSta.callDice.y;			
			gameSta.jiaoButton.x=gameSta.callButton.x-9;
			gameSta.piButton.x=gameSta.kaiButton.x-9;
			gameSta.piButton.y=gameSta.jiaoButton.y=gameSta.arrowDown.y-18;			
			gameSta.numOne.x=view.gameLayer.width*0.4-40;			
			gameSta.numTen.x=view.gameLayer.width*0.4-130;
			
			gameSta.numTen.gotoAndStop(10);
			gameSta.numOne.gotoAndStop(1);
			gameSta.numTen.visible=false;
			gameSta.numOne.y=gameSta.numTen.y=gameSta.otherBtn1.y;
			gameSta.numArrowDown.x=gameSta.numArrowUp.x=(gameSta.numOne.x-gameSta.numTen.x)*0.5+gameSta.numTen.x;
			gameSta.numArrowDown.scaleY=-1;
			
			//监听事件
			gameSta.arrowDown.addEventListener(MouseEvent.CLICK,diceNumChange);
			gameSta.arrowUp.addEventListener(MouseEvent.CLICK,diceNumChange);
			
			gameSta.numArrowUp.addEventListener(MouseEvent.CLICK,diceNumChange);
			gameSta.numArrowDown.addEventListener(MouseEvent.CLICK,diceNumChange);
			
			
			//叫骰的显示框及其内容
			
			showDiceText.x=view.gameLayer.width-45-showDiceText.width*0.5;;
			showDiceText.y=showDiceText.height*0.5+45;			
			view.gameLayer.addChild(showDiceText);
			
			//摇骰动画和骰子内容显示
			
			
			changeDiceBox.x=view.gameLayer.width-5-changeDiceBox.width*0.5;
			changeDiceBox.y=changeDiceBox.height*0.5+180;	
			changeDiceBox.name="changeDice";
			view.gameLayer.addChild(changeDiceBox);
			
			//测试按钮部分
			var btnReady:chairState=new chairState();			
			btnReady.addEventListener(MouseEvent.CLICK,gameReady);
			view.gameLayer.addChild(btnReady);
			btnReady.x=view.gameLayer.width*0.5;
			btnReady.y=view.gameLayer.height*0.5;
			btnReady.name="btnReady";
			btnReady.username="";
			
			var timeCards:Label=new Label();
			timeCards.text="";
			view.gameLayer.addChild(timeCards);
			timeCards.width=50;
			timeCards.height=30;
			timeCards.x=100;
			timeCards.y=50;
			timeCards.name="timeCards";
			
			
			//动画停止部分
			showDiceText.textDice.gotoAndStop(1);
			showDiceText.textOne.gotoAndStop(1);
			showDiceText.textTen.gotoAndStop(1);
			showDiceText.textTen.visible=false;
			changeDiceBox.changeDiceMc.gotoAndStop(1);
			changeDiceBox.diceOne.gotoAndStop(6);
			changeDiceBox.diceTwo.gotoAndStop(6);
			changeDiceBox.diceThree.gotoAndStop(6);
			changeDiceBox.diceFour.gotoAndStop(6);
			changeDiceBox.diceFive.gotoAndStop(6);
			view.gameLayer.addChild(diceText);
			diceText.name="diceText";
			diceText.visible=false;
			gameSta.callDice.stop();
			gameSta.box.visible=false;
			gameSta.specialBtn.visible=false;
			
			for (var i:int=0;i<playerNum;i++)
			{
				var playPic:gamePlayer=new gamePlayer();				
				view.gameLayer.addChild(playPic);						
				gameSeatSet(playPic,userList[i]["seatX"],userList[i]["seatY"]);
				if(userList[i]["ready"]==false)
				{
					playPic.alpha=0.5;
				}
			}
			
			
		}
		/**
		 *游戏开始，获取服务器数据并处理
		 *
		 */	
		
		private function gameBegin(gameInfo:Object):void
		{
			
			var gameTime:int=gameInfo.gameTime;			
			nowCall=gameInfo.playNow;
			myDiceArray=gameInfo.myDice;				
			var diceMovieclip:diceChangeShow=new diceChangeShow();
			view.gameLayer.alpha=0.43;
			view.moveLayer.addChild(diceMovieclip);
			diceMovieclip.x=view.gameLayer.width*0.5;
			diceMovieclip.y=view.gameLayer.height*0.5;
			diceMovieclip.scaleX=diceMovieclip.scaleY=2;
			view.moveLayer.visible=true;	
			diceMovieclip.name="diceMovieClip";
			changeTimer.start();
			diceMovieclip.addEventListener(MouseEvent.CLICK,changeDiceMovie);
			changeTimer.addEventListener(TimerEvent.TIMER,changeDiceMovie);
			
			//test测试
			
		}
		private var changeTimer:Timer=new Timer(3000,0);
		private function changeDiceMovie(e:Event=null):void
		{
			changeTimer.reset();
			changeTimer.removeEventListener(TimerEvent.TIMER,changeDiceMovie);
			(view.moveLayer.getChildByName("diceMovieClip") as diceChangeShow).removeEventListener(MouseEvent.CLICK,changeDiceMovie);
			(view.moveLayer.getChildByName("diceMovieClip") as diceChangeShow).diceOne.gotoAndStop(myDiceArray[0]+1);
			(view.moveLayer.getChildByName("diceMovieClip") as diceChangeShow).diceTwo.gotoAndStop(myDiceArray[1]+1);
			(view.moveLayer.getChildByName("diceMovieClip") as diceChangeShow).diceThree.gotoAndStop(myDiceArray[2]+1);
			(view.moveLayer.getChildByName("diceMovieClip") as diceChangeShow).diceFour.gotoAndStop(myDiceArray[3]+1);
			(view.moveLayer.getChildByName("diceMovieClip") as diceChangeShow).diceFive.gotoAndStop(myDiceArray[4]+1);	
			(view.moveLayer.getChildByName("diceMovieClip") as diceChangeShow).changeDiceMc.gotoAndStop(1);
			Tweener.addTween(view.moveLayer.getChildByName("diceMovieClip"),{scaleX:1,scaleY:1,time:0.5,transition:"easeInBounce"});
			Tweener.addTween(view.moveLayer.getChildByName("diceMovieClip"),{x:view.gameLayer.getChildByName("changeDice").x,y:view.gameLayer.getChildByName("changeDice").y,time:0.5,transition:"easeInBounce",onComplete:loadDice});
			loadDice();
			
		}
		private function loadDice():void
		{			
			changeDiceBox.diceOne.gotoAndStop(myDiceArray[0]+1);
			changeDiceBox.diceTwo.gotoAndStop(myDiceArray[1]+1);
			changeDiceBox.diceThree.gotoAndStop(myDiceArray[2]+1);
			changeDiceBox.diceFour.gotoAndStop(myDiceArray[3]+1);
			changeDiceBox.diceFive.gotoAndStop(myDiceArray[4]+1);	
			changeDiceBox.changeDiceMc.gotoAndStop(1);
			view.moveLayer.removeChild(view.moveLayer.getChildByName("diceMovieClip"));
			view.moveLayer.visible=false;			
			view.gameLayer.alpha=1;	
			gameRun();
			//			changeTimer.start();
			//			changeTimer.addEventListener(TimerEvent.TIMER,turnPlayerBtn);
		}
		private function gameRun():void
		{
			var showTimer:Timer=new Timer(1000,4);
			showTimer.start();
			showTimer.addEventListener(TimerEvent.TIMER,showTimeText);			
			if(nowCall==mySeat)
			{				
				showTimer.addEventListener(TimerEvent.TIMER_COMPLETE,turnPlayerBtn);
			}
			else
			{				
				showTimer.addEventListener(TimerEvent.TIMER_COMPLETE,gamePlayerBtn);
			}
			iTime=0;
		}
		private var iTime:int=0;
		private function showTimeText(e:Event=null):void
		{
			iTime=iTime+1;
			(view.gameLayer.getChildByName("timeCards") as Label).text="还有"+(4-iTime)+"秒可以行动！"
			
		}
		/**
		 *游戏按钮监听增加
		 *
		 */		
		private function turnPlayerBtn(e:Event=null):void
		{			
			gameSta.callButton.addEventListener(MouseEvent.CLICK,callDice);		
			gameSta.kaiButton.addEventListener(MouseEvent.CLICK,openDice);	
			gameSta.piButton.addEventListener(MouseEvent.CLICK,openDice);
		}
		private function gamePlayerBtn(e:Event=null):void
		{
			gameSta.piButton.addEventListener(MouseEvent.CLICK,openDice);
		}
		
		/**
		 *开骰子
		 * @param e
		 *
		 */		
		private function openDice(e:Event):void
		{			
			var openType:int;
			if(e.currentTarget.name=="piButton")
			{
				openType=2					
			}
			else
			{
				openType=1;
			}			
			gameSta.callButton.removeEventListener(MouseEvent.CLICK,callDice);		
			gameSta.kaiButton.removeEventListener(MouseEvent.CLICK,openDice);	
			gameSta.piButton.removeEventListener(MouseEvent.CLICK,openDice);
			var reMessage:RequestMessage = new RequestMessage();
			var proxy:SocketProxy = facade.retrieveProxy(ProxyNames.SocketProxy) as SocketProxy;
			reMessage.type=8;
			reMessage.subtype=9;
			reMessage.params.openType=openType;							
			proxy.send(reMessage);		
		}
		
		/**
		 *叫骰子
		 *
		 */		
		private function callDice(e:Event=null):void
		{
			comChange();
			var callDiceNum:int;
			var diceNum:int=gameSta.callDice.currentFrame-1;
			if(gameSta.numTen.visible==true)
			{
				if(gameSta.numTen.currentFrame==2){callDiceNum=20;}
				else{callDiceNum=gameSta.numOne.currentFrame+10;}				
			}
			else{callDiceNum=gameSta.numOne.currentFrame;}
			if(diceNum==0){diceNum=6}
			sendCallDice(callDiceNum*6+diceNum,0,-1);
			gameSta.callButton.removeEventListener(MouseEvent.CLICK,callDice);		
		}
		private function callDiceMovie(playNow:int):void
		{
			gameSta.callButton.removeEventListener(MouseEvent.CLICK,callDice);		
			gameSta.kaiButton.removeEventListener(MouseEvent.CLICK,openDice);	
			gameSta.piButton.removeEventListener(MouseEvent.CLICK,openDice);
			diceText.x=agameSeatCoordinate[playNow].x;
			diceText.y=agameSeatCoordinate[playNow].y;
			Tweener.addTween(showDiceText,{scaleX:1.2,scaleY:1.2,time:0.1,transition:"easeInBounce"});
			Tweener.addTween(diceText,{scaleX:1.2,time:0.1,transition:"easeInBounce",onComplete:textMove});
		}
		
		private function textMove():void
		{
			Tweener.addTween(showDiceText,{scaleX:1,scaleY:1,time:0.1,transition:"easeInBounce"});
			Tweener.addTween(diceText,{scaleX:1,time:0.1,transition:"easeInBounce"});
		}
		private function sendCallDice(diceNum:int,diceType:int,seatNum:int):void
		{
			
			var reMessage:RequestMessage = new RequestMessage();
			var proxy:SocketProxy = facade.retrieveProxy(ProxyNames.SocketProxy) as SocketProxy;
			reMessage.type=8;
			reMessage.subtype=8;
			reMessage.params.callDice=diceNum;
			reMessage.params.callType=diceType;
			reMessage.params.callTarget=seatNum;			
			proxy.send(reMessage);		
		}
		
		
		private function comChange():void
		{			
			Tweener.addTween(view.gameLayer.getChildByName("gameSta"),{x:view.gameLayer.getChildByName("gameSta").x-5,y:view.gameLayer.getChildByName("gameSta").y+5,time:0.008,transition:"easeInBounce",onComplete:removeChange});
			
		}
		private function removeChange():void
		{
			Tweener.addTween(view.gameLayer.getChildByName("gameSta"),{x:view.gameLayer.getChildByName("gameSta").x+5,y:view.gameLayer.getChildByName("gameSta").y-5,time:0.008,transition:"easeInBounce",onComplete:numMoveAdd});
		}
		
		private var numMove:int=0;
		private function numMoveAdd():void
		{
			numMove=numMove+1;
			if(numMove<3)
			{
				comChange();
			}
			else
			{
				numMove=0;
			}
		}
		
		
		
		private function overDice(e:Event):void
		{
			trace("overDice");
			var reMessage:RequestMessage = new RequestMessage();
			var proxy:SocketProxy = facade.retrieveProxy(ProxyNames.SocketProxy) as SocketProxy;
			reMessage.type=8;
			reMessage.subtype=8;
			reMessage.params.callDice=0;
			reMessage.params.callType=0;
			reMessage.params.callTarget=0;	
			proxy.send(reMessage);		
			
		}
		
		/**
		 *叫骰子的上下按钮事件
		 * @param e
		 *
		 */		
		private function diceNumChange(e:Event):void
		{			
			var numChange:String=e.currentTarget.name;			
			var	nowFarme:int=gameSta.callDice.currentFrame;
			var	nowNumOne:int=gameSta.numOne.currentFrame;
			var	nowNumTen:int=gameSta.numTen.currentFrame;
			var nowNum:int=nowNumTen+nowNumOne;
			if(gameSta.numTen.visible==false)
			{
				nowNum=nowNum-10;
			}
			if(nowNumTen==2)
			{
				nowNum=20;
			}
			switch(numChange)
			{
				case "arrowUp":
				{
					nowFarme=nowFarme+1;
					if(nowFarme==7){nowFarme=1}
					gameSta.callDice.gotoAndStop(nowFarme);	
				}
					break;
				case "arrowDown":
				{
					nowFarme=nowFarme-1;
					if(nowFarme==0){nowFarme=6}
					gameSta.callDice.gotoAndStop(nowFarme);	
				}
					break;
				case "numArrowUp":
				{
					nowNum=nowNum+1;
					gameSta.numOne.gotoAndStop(nowNum);
					if(nowNum>20)
					{
						nowNum=20;
					}
					if(nowNum>10)
					{						
						gameSta.numTen.visible=true;
						gameSta.numOne.gotoAndStop(nowNum-10);
						gameSta.numTen.gotoAndStop(10);
					}
					if(nowNum==20){
						gameSta.numTen.gotoAndStop(2);
						gameSta.numOne.gotoAndStop(10);
					}
				}
					break;
				case "numArrowDown":
				{
					nowNum=nowNum-1;
					
					if(nowNum==0)
					{
						nowNum=1;
					}
					if(nowNum>10)
					{						
						gameSta.numTen.visible=true;
						gameSta.numOne.gotoAndStop(nowNum-10);
						gameSta.numTen.gotoAndStop(10);
					}
					if(nowNum<=10)
					{
						gameSta.numTen.visible=false;
						gameSta.numOne.gotoAndStop(nowNum);
					}
					
				}
					break;
			}			
			
		}
		/**
		 *通过椅子的X，Y找到相应的座位
		 * @param _x	椅子的X
		 * @param _y	椅子的Y
		 * @return 		椅子对应桌子的位置gameSeat（0-3）
		 *
		 */	
		private function findThisSeat(_x:int,_y:int):int
		{
			var x:int=gameInfo.deskX-_x;
			var y:int=gameInfo.deskY-_y;			
			var gameSeat:String;
			switch(x+y*2)
			{
				case 2:
				{
					gameSeat="2";
				}
					break;
				
				case 1:
				{
					gameSeat="3";
				}
					break;
				
				case -1:
				{
					gameSeat="1";
				}
					break;
				
				case -2:
				{
					gameSeat="0";
				}
					break;
			}
			
			return int(gameSeat);
		}
		
		private function gameRestart(e:Event):void
		{
			view.testC.visible=false;
			var numRemove:int=view.gameLayer.numChildren;
			diceText.visible=false;
			for(var i:int=0;i<numRemove;i++)
			{
				if(view.gameLayer.getChildAt(i) is gamePlayer)
				{
					view.gameLayer.getChildAt(i).alpha=0.5;
				}
			}
		}
		
		
		
		
	}
	
}
